package com.itheima.chinamobileai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai/mobile")
public class MobileChatController {
    
    @Autowired
    private ChatClient chinaMobileChatClient;
    
    @GetMapping(produces = "text/html;charset=UTF-8")
    public Flux<String> chat(String prompt, String chatId) {
        return chinaMobileChatClient.prompt(prompt)
                .advisors(spec -> spec.param(ChatMemory.CONVERSATION_ID, chatId))
                .stream()
                .content();
    }
}